package org.ishequ.fileaccess;

import org.ishequ.service.FileService;
import android.app.Activity;
import android.os.Bundle;
import android.view.View;
import android.view.View.OnClickListener;
import android.widget.EditText;
import android.widget.Toast;

public class FileAccessActivity extends Activity {

    @Override
    public void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.main);
        findViewById(R.id.save).setOnClickListener(new ButtonClickListener());
    }
    
    private final class ButtonClickListener implements OnClickListener{
		@Override
		public void onClick(View v) {
			EditText fileNameText = (EditText)findViewById(R.id.filename);
			EditText fileContentText = (EditText)findViewById(R.id.content);
			FileService service = new FileService(getApplicationContext());
			try {
//				service.writeToLocal(fileNameText.getText().toString(),fileContentText.getText().toString(),getApplicationContext().MODE_WORLD_READABLE+FileAccessActivity.this.MODE_WORLD_WRITEABLE);
				service.writeToSDCard(fileNameText.getText().toString(),fileContentText.getText().toString());
			} catch (Exception e) {
				Toast.makeText(getApplicationContext(), R.string.msg_error, Toast.LENGTH_SHORT).show();
				e.printStackTrace();
			}
			Toast.makeText(getApplicationContext(), R.string.msg_success, Toast.LENGTH_SHORT).show();
		}
    	
    }
}